package com.mini.cn.goods.job;

import lombok.extern.slf4j.Slf4j;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Trigger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static org.quartz.TriggerBuilder.newTrigger;

/**
 * Created with IntelliJ IDEA.
 * User: fly
 * Date: 2018-09-14
 * Time: 下午3:18
 */
@Configuration
@Slf4j
public class QuartzConfig {

    /**
     * 定时拉取cat数据
     *
     * @return
     */
    @Bean
    public JobDetail dayActionDetail() {
        return JobBuilder.newJob(DayJob.class).
                withIdentity("dayActionJob").storeDurably().build();
    }

    /**
     * 定时每天的活动
     *
     * @return
     */
    @Bean
    public Trigger dayActionJobQuartzTrigger() {
        log.info("catJobQuartzTrigger init");
        //每天凌晨更新 0 */1 * * * ?   0 0 0 * * ?
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.
                cronSchedule("0 0 0 * * ?");
        return newTrigger().forJob(dayActionDetail())
                .withIdentity("dayActionJob")
                .withSchedule(cronScheduleBuilder)
                .build();
    }
    /**
     * vip 初始化
     */
    @Bean
    public JobDetail vipJobDetail() {
        return JobBuilder.newJob(VipCpJob.class).
                withIdentity("vipJob").storeDurably().build();
    }

    /**
     * vip 初始化
     */
    @Bean
    public Trigger vipJobQuartzTrigger() {
        log.info("lotteryJobQuartzTrigger init");
        //每个月1号   0 0 0 1 * ?
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.
                cronSchedule("0 0 0 1 * ?");
        return newTrigger().forJob(vipJobDetail())
                .withIdentity("vipJob")
                .withSchedule(cronScheduleBuilder)
                .build();
    }
}
